<template>
    <div>
        <!--      搜索  创建-->
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item>
                <el-input clearable v-model="form.name" style="width: 300px" placeholder="姓名"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="query">搜索</el-button>
            </el-form-item>
        </el-form>
      
        <el-table :data="tableData" border>
            <el-table-column
                    fixed
                    prop="name"
                    label="姓名"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="sex"
                    label="性别"
                    align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.sex == '0'">男</span>
                    <span v-if="scope.row.sex == '1'">女</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="education"
                    label="教育程度"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="tel"
                    label="联系电话"
                    align="center">
            </el-table-column>
            <!-- <el-table-column
                    prop="state"
                    label="状态"
                    align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.state == '0'">未办结</span>
                    <span v-if="scope.row.state == '1'">已办结</span>
                </template>
            </el-table-column> -->
            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center"
                    width="200">
                <template slot-scope="scope"> 
                    <el-button
                            type="success"
                            size="mini"
                            @click="handleEdit(scope.row)">详情
                    </el-button>
                    <el-button
                            v-show="scope.row.state === '1'"
                            type="primary"
                            size="mini"
                            @click="transfer(scope.row)">受理
                    </el-button>
                    <el-button
                            v-show="scope.row.state !== '1'"
                            type="info"
                            size="mini"
                            disabled>已受理
                    </el-button>
                    <!-- <el-button
                            v-show="scope.row.state==='0'"
                            type="danger"
                            size="mini"
                            @click="handleDelete(scope.row)">删除
                    </el-button> -->
                </template>
            </el-table-column>
        </el-table>
<!--        分页-->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNo"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next"
                :total="totalRecord" class="text-center mt10">
        </el-pagination>

        <!-- 受理弹出框 -->
        <el-dialog title="审核" :visible.sync="transferVisible"  width="650px">
            <el-radio-group v-model="radio" style="margin-left: 125px;margin-bottom: 20px;margin-top: 30px">
                <el-radio style="margin-left: 35px" :label="1" border>受理通过</el-radio>
                <el-radio style="margin-left: 35px" :label="0" border>不予通过</el-radio>
            </el-radio-group>

            <el-form v-show="this.radio =='0'">
                <el-form-item label="原因：">
                    <el-input
                            type="textarea"
                            v-model="reason"
                            autosize
                            placeholder="请填写原因"
                    >
                    </el-input>
                </el-form-item>
            </el-form>

            <div style="width: 160px; margin-left: 445px">
                <el-button @click="transferVisible = false">取 消</el-button>
                <el-button type="primary" @click="transfersave">确 定</el-button>
            </div>
        </el-dialog>

<!--        修改弹出框-->
        <el-dialog title="详情" :visible.sync="dialogFormVisibleEdit">
            <el-form :model="ruleFormEdit" :rules="rulesEdit" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <el-form-item label="姓名" prop="name">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.name"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleFormEdit.sex"></el-input> -->
                        <el-select style="width: 320px" v-model="ruleFormEdit.sex" placeholder="请选择">
                            <el-option label="男" value="0">男</el-option>
                            <el-option label="女" value="1">女</el-option>
                        </el-select>
                    </div>
                </el-form-item>
                <el-form-item label="出生日期" prop="birth">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleFormEdit.birth"></el-input> -->
                        <el-date-picker 
                            style="width: 320px"
                            v-model="ruleFormEdit.birth"  
                            type="date"  
                            placeholder="选择日期">
                        </el-date-picker>

                    </div>
                </el-form-item>
                <el-form-item label="教育程度" prop="education">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.education"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="民族" prop="nation">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.nation"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="家庭住址" prop="address">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.address"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="身份证号" prop="idcard">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.idcard"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="联系电话" prop="tel">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.tel"></el-input>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibleEdit = false">取 消</el-button>
                <el-button type="primary" @click="yes">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>


    export default {

        name: 'test',

        data() {
            return {
                radio:'',
                transferid:'',
                reason:'',//未通过原因
                activeName:'first',
                tableData: [],
                pageNo: 1,
                pageSize: 10,
                totalRecord: 0,
                totalPage: 0,
                transferVisible:false,//受理弹出框
                dialogFormVisibleEdit:false, //修改弹出框
                form:{},  //创建按钮的表单
                //创建表单
                ruleForm: {
                    title: '',
                    content: '',
                },
                //修改表单
                ruleFormEdit:{
                    title: '',
                    content: '',
                },
               
                //修改验证
                rulesEdit: {
                    name: [
                        { required: true, message: '请输入标题', trigger: 'blur' }
                    ],
                    sex: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                    birth: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                    address: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],

                    education: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                    nation: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                    idcard: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                    tel: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                },
                formLabelWidth: '120px',
                cid:''
            }
        },

        props: {},

        components: {},

        computed: {},

        methods: {
            // 初始化
            async init() {
                const res = await this.$http('selturnlist',{
                    pageNo: this.pageNo,
                    pageSize: this.pageSize
                })
                this.tableData = res.results
                console.log('res',this.tableData)
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
                console.log(res)
            },
            handleClick(row) {
                console.log(row);
            },
            //分页
            async handleSizeChange(val) {
                this.pageSize = val;
                this.init();
            },
            async handleCurrentChange(val) {
                this.pageNo = val;
                this.init();
            },
            
            //编辑
            handleEdit(row){
                this.dialogFormVisibleEdit = true
                this.cid = row.id
                this.ruleFormEdit = row
            },
            //点击确定即可完成编辑
            async yes(){
                var timestamp = this.ruleFormEdit.birth;
                console.log('birth',timestamp)
                var d = new Date(timestamp);    //根据时间戳生成的时间对象
                var date = (d.getFullYear()) + "-" +
                    (d.getMonth() + 1) + "-" +
                    (d.getDate())
                this.ruleFormEdit.birth = date
                const res = await this.$http('createorder',{
                    id:this.cid,
                    name:this.ruleFormEdit.name,
                    sex:this.ruleFormEdit.sex,
                    birth:this.ruleFormEdit.birth,
                    education:this.ruleFormEdit.education,
                    nation:this.ruleFormEdit.nation,
                    address:this.ruleFormEdit.address,
                    idcard:this.ruleFormEdit.idcard,
                    tel:this.ruleFormEdit.tel
                })
                //this.dialogFormVisibleEdit = false
                if (res.count === 1) {
                    this.$message({
                        message: '编辑成功',
                        type: 'success'
                    });
                    this.dialogFormVisibleEdit = false
                    this.init()
                } else {
                    this.$message({
                        message: '编辑失败',
                        type: 'error'
                    });
                }
            },
            //删除
            async handleDelete(row){
                this.$confirm('将永久删除该内容, 是否继续?', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    const res =await this.$http('createorder',{
                        id:row.id,
                        del_flag:'1'
                    })
                    this.init()
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            //点击受理
            async transfer(row){
                this.transferVisible = true
                this.transferid = row.id
            },
            //受理确认
            async transfersave(){
               const res =await this.$http('updateEvnState1',{
                        id:this.transferid,
                    })
                    this.init()
                    this.transferVisible = false
                if(this.radio == '1'){
                    const res1 =await this.$http('createflow',{
                        id:this.transferid,
                        state:'2'
                    })
                }else if(this.radio == '0'){
                    const res1 =await this.$http('createflow',{
                        id:this.transferid,
                        state:'3',
                        reason:this.reason
                    })
                }
           
            },
            //搜索
            async query(){
                const res = await this.$http('selecteventlist',{
                    name:this.form.name
                })
                this.tableData = res.results
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
            }
        },

        watch: {},

        mounted() {
            this.init();
        },

    }
</script>

<style scoped>

</style>
